DCT transformation

10 views (last 30 days)
amitesh kumar on 15 Feb 2011
Answered: Robert Brown on 18 Apr 2021
hello i am trying to apply DCT transformation on image of size 512*512. for applying DCT i use following code
I = im2double(norm); T = dctmtx(8); dct = @(block_struct) T * block_struct.data * T'; D = blockproc(I,[8 8],dct);
and for Inverse DCT i am using the following one
mask = [1 1 1 1 0 0 0 0 1 1 1 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; B2 = blockproc( D,[8 8],@(block_struct) mask .* block_struct.data); invdct = @(block_struct) T' * block_struct.data * T; I2 = blockproc(B2,[8 8],invdct);
here in IDCT , what is actual importance of 'mask'. here matrix shown for mask is 8*8 as i am converting the image also in 8*8 block. if i like maintain the block of 32*32, than what is the procedure for writing 'mask' matrix. so my confusion is regarding importance of masking here and how to write mask matrix for 32*32. if anybody having any idea , plz help me . thanx in adv.....

Robert Brown on 18 Apr 2021
Couldn't find your image, so I found 'rice.png' within MATLAB
Display the rice.png image, ising imagesc to autoscale and display the image.
figure
imagesc(I)
T = dctmtx(8);
dct = @(block_struct) T * block_struct.data * T'
D = blockproc(I,[8 8],dct);
In your code, you had mask as a long 1x64 vector, and I think you meant to have it as an 8x8 matrix. I manually put the semicolons after each 8 elements of the mask vector, to turn it into an 8x8 matrix. More elegantly, I could have used the command mask = reshape(mask,8,8) to reshape the 1x64 vector into an 8x8 matrix. Once I made this change, your code ran successfully, and computed new image I2, which I display here using imagesc instead of image, since imagesc autoscales the image before displaying it
mask = [1 1 1 1 0 0 0 0; 1 1 1 0 0 0 0 0; 1 1 0 0 0 0 0 0; 1 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0]
B2 = blockproc( D,[8 8],@(block_struct) mask .* block_struct.data);
invdct = @(block_struct) T' * block_struct.data * T
I2 = blockproc(B2,[8 8],invdct);
figure
imagesc(I2)

Categories

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by