Step 4- Apply Disrete Cosine Transform to the image
DCT_tf_img = dct_full_image(IMG,macrobock_size,Q);
Step 4- Apply Disrete Cosine Transform to the image
DCT_tf_img = dct_full_image(IMG,macrobock_size,Q);
Refer this video to understand more.
Now lets look in to the function
function transformed = dct_full_image(img,macroblock_size,Q)
%k1 = macroblock row index
%k2 = macroblock column index
%macroblock_size = number of side pixels in a macroblock
for i = 1:size(img,1)
for j = 1:size(img,2)
transformed(i,j)={ floor(dct2(cell2mat(img(i,j)))./Q ) };
end
end
end
Here I have used the inbuilt DCT transform. But before applying we have to convert cell arrays to matrices. Then we divide it by quantization matrix. These are predefined. Then we round off so that lots of zero components in the high frequency side of the matrix which is right bottom corner.