m=512; n=512;
fin=fopen('peppers.raw','r');
X=fread(fin,m*n,'uint8=>uint8'); fclose(fin);
Y=reshape(X,m,n);
A = Y ;
[M,N] = size(A) ;
nx = 8 ; ny = 8 ;
m = M/nx ; n = M/ny ;
l = size (A) ./ [m n];
T = mat2cell (A, repmat (m, l(1), 1), repmat (n, l (2), 1));
M = cellfun(@mean,T,'un',0) ;
M = cellfun(@mean,M,'un',0) ;
M = cell2mat(M)

%²Ä¤GÃD
M = M - 128
B = dct2(M)

%²Ä¤TÃD
q_mtx =     [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];
%PErforming Quantization by Dividing with q_mtx on blocks of 8 by 8
c = @(block_struct) (block_struct.data) ./ q_mtx;        
B2 = blockproc(B,[8 8],c)

%²Ä¥|ÃD
 Q4 = ZigZagscan(B2)
 
 %²Ä¤­ÃD
 process("peppers.raw",512,512);