\frametitle {Matlab code to simulate a JPEG compression cycle (3)} \begin{lstlisting} % Dequantize DCT coefficients y = blockproc( y, [8 8], @(block_struct) block_struct.data .* q_y); cb = blockproc(cb, [8 8], @(block_struct) block_struct.data .* q_c); cr = blockproc(cr, [8 8], @(block_struct) block_struct.data .* q_c); % Inverse DCT y = blockproc( y ./ q_max, [8 8], idct); cb = blockproc(cb ./ q_max, [8 8], idct); cr = blockproc(cr ./ q_max, [8 8], idct); % Up-sample chroma upsample_filter_1d = [1 3 3 1] / 4; upsample_filter = upsample_filter_1d' * upsample_filter_1d; cb = conv2(upsample_filter, upsample(upsample(padarray(cb, [1 1], 'replicate'), 2)', 2)'); cb = cb(4 : size(cb, 1) - 4, 4 : size(cb, 2) - 4); cr = conv2(upsample_filter, upsample(upsample(padarray(cr, [1 1], 'replicate'), 2)', 2)'); cr = cr(4 : size(cr, 1) - 4, 4 : size(cr, 2) - 4); % Concatenate the channels jpeg_result = ycbcr2rgb(cat(3, y, cb, cr)); end \end{lstlisting}