How can I take the DCT coefficients in each 8x8 block as an image?

16 views (last 30 days)
So basically, I have to divide up an entire image into 8x8 blocks, and perform the 2D DCT for each block, outputting the results into a new image such that the new image shows DCT coefficients for each corresponding image block.
So far this is what I have;
% code
I = imread('lenagray.jpg');
I = im2double(I);
T = dctmtx(8);
dct = @(block_struct) T * block_struct.data * T';
B = blockproc(I,[8 8],dct);
figure;
imagesc(B)
just need help with making a image of the DCT coefficients

Answers (2)

Walter Roberson
Walter Roberson on 9 Nov 2015
.jpg images are always RGB (3 dimensional) even when the appear to be grey, so the result of the imread() will be 3 dimensional. im2double() of something 3 dimensional results in something 3 dimensional. blockproc() of something 3 dimensional will extract 3 dimensional blocks. You then try to do a matrix multiplication of the 3 dimensional block, which is going to fail.
You may wish consider using rgb2gray()
  4 Comments
Osman
Osman on 9 Nov 2015
This is the exact questions im working on;
Write a script to divide up an entire image (assume grayscale) into 8x8 blocks, and perform the 2D DCT for each block, outputting the results into a new image (such that the new image shows DCT coefficients for each corresponding image block). [HINT]: you can use the blockproc() function in matlab to simplify this process
Walter Roberson
Walter Roberson on 9 Nov 2015
imshow() with [] is about the best you can do, but you might want to get fancier by putting together the coefficients for each of the Y, Cr, Cb panes to produce a colored version of the data.

Sign in to comment.


GOKUL REDDY
GOKUL REDDY on 25 May 2020
I = imread('lenagray.jpg');
I = im2double(I);
T = dctmtx(8);
dct = @(block_struct) T * block_struct.data * T';
B = blockproc(I,[8 8],dct);
figure;
imagesc(B)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!