How can I take the DCT coefficients in each 8x8 block as an image?
16 views (last 30 days)
Show older comments
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
0 Comments
Answers (2)
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
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.
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)
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!