Image Compression: How to use blockproc function with dct2 inside

9 次查看(过去 30 天)
For the uploaded image below with 536x704 pixel size, my code reads the image, converts to ycbcr and subsamples, then with dct tries to make 8x8 block with 4:2;0 format and choose the top 6th row of the luminance.
My code:
I = imread('Flooded_house.jpg','jpg');
%converting to ycbcr
YCbCr = rgb2ycbcr(I);
Y = YCbCr(:,:,1);
Cb = YCbCr(:,:,2);
Cr = YCbCr(:,:,3);
%sub-sampling
Sub_Cb = Cb(1:2:end, 1:2:end);
Sub_Cr = Cr(1:2:end, 1:2:end);
%Now computing the 8x8 block DCT transform coefficients in 4:2:0 format
DCT_Trans = @(block_struct) dct2(block_struct.data);
DCT_Y = blockproc(Y, [8 8], DCT_Trans);
DCT_Cb = blockproc(Sub_Cb, [8 8], DCT_Trans, 'PadPartialBlocks', true);
DCT_Cr = blockproc(Sub_Cr, [8 8], DCT_Trans, 'PadPartialBlocks', true);
%Part (a)
%putting the first block of the DCT image
First_Block = DCT_Trans(1:8,1:8);
imshow(First_Block)
%computing the first 2 blocks in the 6th row from the top of the luminance
%component
Sixth_Block = DCT_Trans(41:48,1:8);
imshow(Sixth_Block)
Sixth_Block_p2 = DCT_Trans(41:48,9:16);
imshow(Sixth_Block_p2)
Error Code:
Error using Encoder_a>@(block_struct)dct2(block_struct.data)
Too many input arguments.
Error in Encoder_a (line 31)
First_Block = DCT_Trans(1:8,1:8);

回答(1 个)

Abolfazl Chaman Motlagh
you created DCT_Trans function for blockprop . it's a function which takes structure as input. if you pass structure S to it's input, it takes dct of S.data. so the line
First_Block = DCT_Trans(1:8,1:8);
and all lines like this, return error. because (1:8,1:8) are two input. and they are not structure.
if you wanna call your transformed image you should call DCT_Y, DCT_Cb and DCT_Cr .
don't you mean :
First_Block = DCT_Y(1:8,1:8);
???

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by