MATLAB: How to divide gray scale image into 8×8 blocks and access each block separately to apply dct2 on the block

binarydctdividegrayscale

I want to divide the grayscale image which in my case is the 'cameraman.tif' into 8×8 blocks then run dct2 on each block to
later hide a binary watermark image into each block.
So far I tried blockproc and many other methods but none of them satisfy my needs.

Best Answer

file = 'cameraman.tif';
im=imread(file);
imshow(im);
In order to use blockproc you have to use a function that accpts blocksstructure, that's why you need to use something like this
imModified = blockproc(im,[8 8],@(blkStruct) dct2(blkStruct.data));
imshow(imModified)
I hope this answers your question
Related Question