Clear Filters
Clear Filters

Image Compression: How to use blockproc function with dct2 inside

10 views (last 30 days)
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_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(;
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);
%computing the first 2 blocks in the 6th row from the top of the luminance
Sixth_Block = DCT_Trans(41:48,1:8);
Sixth_Block_p2 = DCT_Trans(41:48,9:16);
Error Code:
Error using Encoder_a>@(block_struct)dct2(
Too many input arguments.
Error in Encoder_a (line 31)
First_Block = DCT_Trans(1:8,1:8);

Answers (1)

Abolfazl Chaman Motlagh
Abolfazl Chaman Motlagh on 11 Mar 2022
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 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);





Community Treasure Hunt

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

Start Hunting!